package com.aaa.service;

import com.aaa.dao.CourseTypeDao;
import com.aaa.dao.impl.CourseTypeDaoImpl;
import com.aaa.entity.CourseEntity;
import com.aaa.entity.CourseTypeEntity;
import com.aaa.entity.Message;
import com.aaa.entity.Pager;
import com.aaa.util.PageUtil;

import java.util.Map;

public class CourseTypeServiceImpl implements CourseTypeService {
    CourseTypeDao dao=new CourseTypeDaoImpl();

    @Override
    public Pager queryAll(int pageNo) {
      int pageSize= PageUtil.PAGE_SIZE;
      return dao.queryAll(pageNo,pageSize);
    }

    @Override
    public Message Update(CourseTypeEntity courseTypeEntity) {
        Message message=new Message();
        int result=-1;
        if(courseTypeEntity.getTypeId()==0){
            result=dao.type_add(courseTypeEntity);
            if (result>=1){
                message=new Message(200,"录入成功");
            }else {
                message=new Message(300,"录入失败");
            }
        }else {
            result=dao.type_update(courseTypeEntity);
            if (result>=1){
                message=new Message(200,"修改成功");
            }else {
                message=new Message(300,"修改失败");
            }
        }
        return message;
    }

    @Override
    public Map queryOne(int id) {
        return dao.queryOne(id);
    }

    @Override
    public int delete(int id) {
        return dao.type_delete(id);
    }


}
